package com.example.controller;

import java.util.Arrays;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import com.example.pojo.SignIn;
import com.example.service.ISignInService;
import io.swagger.annotations.Api;
/**
 * <p>
 * 签到表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-05-12
 */
@RestController
@RequestMapping("/signIn")
@Api(tags = "签到表",value = "")
@CrossOrigin(allowCredentials = "true")
public class SignInController {

    @Autowired
    private ISignInService isis;

    @ApiOperation(value = "查询签到表")
    @GetMapping("/query")
    public ResultVo getSignInPageInfo(@RequestParam("wid") Integer workid) {
        if (workid == null){
            return ResultVo.error("请登录后查看！");
        }
        return ResultVo.response(isis.selectListSigInByWorId(workid));
    }

    @ApiOperation(value = "新增签到表")
    @PostMapping("/add")
    public ResultVo addSignIn(@RequestBody SignIn signIn) {
        if (signIn != null){
            isis.addSignIn(signIn);
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @ApiOperation(value = "修改签到表")
    @PutMapping("/update")
    public ResultVo updateSignIn(@RequestBody SignIn signIn) {
        if (isis.updateById(signIn)) {
            return ResultVo.success("修改成功!");
        }
        return ResultVo.error("修改失败!");
    }

    @ApiOperation(value = "删除签到表")
    @DeleteMapping("/delete")
    public ResultVo deleteSignIn(Integer[] ids){
        if(isis.removeByIds(Arrays.asList(ids))){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }
}
